//
//  PPSettingTableViewController.m
//  pet
//
//  Created by 陈无忌 on 1/14/15.
//  Copyright (c) 2015 whalefin. All rights reserved.
//

#import "PPSettingTableViewController.h"
#import "supportingHeadFiles.h"
#import "PPSystemConfiguraton.h"

@interface PPSettingTableViewController ()
@property (weak, nonatomic) PPSystemConfiguraton *config;

@end

@implementation PPSettingTableViewController
- (PPSystemConfiguraton *)config
{
    if (!_config) {
        _config = [PPSystemConfiguraton sharedSystemConfiguration];
    }
    return _config;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 2 && indexPath.row == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/US/app/id887775175"]];
    }else if (indexPath.section == 3) {
        //exit
        NSString *url = [PPAPIList getAPIList].PPLogout;
        NSDictionary *params = @{@"userId":@(self.config.userInfo.id)};
        [httpRequst POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject){
            if (self.config.isEaseMobLogin) {
                [[EaseMob sharedInstance].chatManager asyncLogoff];
                self.config.isEaseMobLogin = NO;
            }
            self.config.isLogin = NO;
            UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *theInitialViewController = [secondStoryboard instantiateInitialViewController];
            self.navigationController.navigationBar.hidden = YES;
            [self.navigationController pushViewController:theInitialViewController animated:YES];
        }failure:^(AFHTTPRequestOperation *operation, NSError *error){
            NSLog(@"error is %@",error);
        }];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
